<?php
/**
 * Free Uch
 *
 * @category   FreeUch
 * @copyright  Copyright 2009 lordharrdlee(http://www.lordharrdlee.cn)
 * @author     lordharrdlee<lordharrdlee@gmail.com>
 * @version    $Id: Hotel.php 10 2010-01-14 10:31:01Z lordharrdlee $
 */
/**
 * Action_Hotel
 * @author     lordharrdlee<lordharrdlee@gmail.com>
 */
class Action_Hotel extends Action_Base {
    protected $useModel = true;

    public function index() {
        $this->view->actives['index'] = ' class="active"';
        $this->display('index');
    }

    public function tuijian() {
        $cid=intval($_GET['cid']);
        if(!empty ($cid)) {
            $tj = $this->model->getRecommoned($cid);
            echo '<div id="tagcontent1" class="tagcontent selectTag">';
            echo '<div class="index_pic"><ul>'."\n";
            foreach($tj[0] as $obj) {
                echo '<li><a href="freeuch.php?mod=hotel&act=hotel&cid='.$cid.'&hid='.$obj->id.'"><IMG height="92" src="'.$obj->Picture.'" width="124">'.$obj->Name.'</a></li>'."\n";
            }
            echo "</ul></div>"."\n";
            echo '<div class="index_price"><H4>180元以下酒店</H4><ul>'."\n";
            foreach($tj[1] as $obj) {
                echo '<li><span>'.$obj->mjiage.'元</span><a href="freeuch.php?mod=hotel&act=hotel&cid='.$cid.'&hid='.$obj->id.'">'.$obj->Name.'</a></li>'."\n";
            }
            echo "</ul></div>"."\n";
            echo '<div class="index_price"><H4>180元-240元酒店</H4><ul>'."\n";
            foreach($tj[2] as $obj) {
                echo '<li><span>'.$obj->mjiage.'元</span><a href="freeuch.php?mod=hotel&act=hotel&cid='.$cid.'&hid='.$obj->id.'">'.$obj->Name.'</a></li>'."\n";
            }
            echo "</ul></div>"."\n";
            echo '<div class="index_price"><H4>240元-400元酒店</H4><ul>'."\n";
            foreach($tj[3] as $obj) {
                echo '<li><span>'.$obj->mjiage.'元</span><a href="freeuch.php?mod=hotel&act=hotel&cid='.$cid.'&hid='.$obj->id.'">'.$obj->Name.'</a></li>'."\n";
            }
            echo "</ul></div></div>";
        }
    }

    public function search() {
        $this->view->actives['search'] = ' class="active"';

        $data = array();
        $cid = intval($_GET['cid']);
        $cid=empty($cid)?53:$cid;
        $this->view->cid = $cid;
        $url1="freeuch.php?mod=hotel&act=search&cid=$cid";
        $data['cityid']=$cid;
        $ck="_c".$cid;

        if(!empty($_GET['tm1']) && !empty($_GET['tm2'])) {
            $tm1=$_GET['tm1'];
            $tm2=$_GET['tm2'];
            setcookie('tm1',$tm1);
            setcookie('tm2',$tm2);
        }else {
            $tm1='';
            $tm2='';
        }
        $mp1=empty($_GET['minprice'])?'':$_GET['minprice'];
        $this->view->mp1 = $mp1;
        if($mp1!='') {
            $url1.='&minprice='.$mp1;
            $data[minprice]=$mp1;
            $ck.="_min".$mp1;
        }
        $mp2=empty($_GET['maxprice'])?'':$_GET['maxprice'];
        $this->view->mp2 = $mp2;
        if($mp2!='') {
            $url1.='&maxprice='.$mp2;
            $data[maxprice]=$mp2;
            $ck.="_max".$mp2;
        }
        if(!empty($_GET['xj'])) {
            $url1.='&xj='.$_GET['xj'];
            $data[rank]=$_GET['xj'];
            $ck.="_xj".$_GET['xj'];
        }

        $k1=empty($_GET['k1'])?'':$_GET['k1'];
        $this->view->k1 = $k1;
        if($k1!='') {
            $url1.='&k1='.$k1;
            $data[key]=$k1;
            $ck.="_k1".$k1;
        }
        if(!empty($_GET['lsid'])) {
            $url1.='&lsid='.$_GET['lsid'];
            $data[lsid]=$_GET['lsid'];
            $ck.="_lsid".$_GET['lsid'];
        }
        if(!empty($_GET['bid'])) {
            $url1.='&bid='.$_GET['bid'];
            $data[bid]=$_GET['bid'];
            $ck.="_bid".$_GET['bid'];
        }

        $k2=empty($_GET['k2'])?'':$_GET['k2'];
        $this->view->k2 = $k2;
        if($k2!='') {
            $url1.='&k2='.$k2;
            $data[hn]=$k2;
            $ck.="_k2".$k2;
        }
        $this->view->pxUrl=$url1;
        $px=empty($_GET['px'])?1:$_GET['px'];
        if($px!=1) {
            $url1.='&px='.$_GET['px'];
            $data[px]=$_GET['px'];

        }
        $ck.="_px".$px;
        if(!empty($_GET['p'])) {
            $data[pg]=$_GET['p'];
            $p=$_GET['p'];
        }else {
            $p=1;
        }
        $ck.="_p".$p;
        if(empty($_GET['k2']) && empty($_GET['k1'])) {
            $nocache = 0;
        }else {
            $nocache = 1;
        }
        $strjson=$this->model->getFile("chain",array('cityid'=>$cid));
        $this->view->ls=json_decode($strjson,true);
        $strjson=$this->model->getFile("shangyequ",array('cityid'=>$cid));
        $this->view->cbd=json_decode($strjson,true);

        $strjson=$this->model->getFile("search",$data,$nocache,43200);// 缓存0.5天
        $this->view->json=json_decode($strjson,true);
        if(empty($this->view->json[Size]))$this->view->json[Size]=1;
        $this->view->pHtml='<div id="pages">'.$this->model->getPage($this->view->json[total],"\t<a href='".$url1."&p={p}'{b}>{t}</a>\t\n",$p).'</div>';
        $this->view->px = $px;
        $this->view->pxactives[$px] = ' id="list_current"';
        $this->display('search');
    }

    public function hotel() {
        $this->view->actives['search'] = ' class="active"';

        $cid = intval($_GET['cid']);
        $hid = intval($_GET['hid']);
        $cid=empty($cid)?53:$cid;
        $hid=empty($hid)?0:$hid;
        if(!empty($_POST['tm3'])&&!empty($_POST['tm4'])) {
            $tm1=$_POST['tm3'];
            $tm2=$_POST['tm4'];
            setcookie('tm1',$tm1);
            setcookie('tm2',$tm2);
        }elseif(!empty($_COOKIE['tm1'])&&!empty($_COOKIE['tm2'])) {
            $tm1=$_COOKIE['tm1'];
            $tm2=$_COOKIE['tm2'];
        }else {
            $tm1='';
            $tm2='';
        }
        
        $strjson=$this->model->getFile('hotelinfo',array('hid'=>$hid,'cityid'=>$cid),0,216000);
        $this->view->hotel=json_decode($strjson,true);
        $strjson=$this->model->getFile('room',array('hid'=>$hid,'tm1'=>$tm1,'tm2'=>$tm2),1);
        $this->view->Rm=json_decode($strjson,true);
        $strjson=$this->model->getFile('around',array('hid'=>$hid,'cityid'=>$cid));
        $this->view->rd=json_decode($strjson,true);

        $tm1 = strtotime($this->view->Rm['tm1']);
        $tm2 = strtotime($this->view->Rm['tm2']);
        $timediff = abs($tm1-$tm2)/86400;
        $daydiff = intval($timediff);
        $daydiff = $daydiff <= 4 ? $daydiff : 4;
        $this->view->daydiff = $daydiff;
        for($i=1;$i<=$daydiff;$i++) {
            $days[] = date("Y-m-d",$tm1);
            $tm1 += 86400;
        }
        switch ($daydiff){
            case 1:
                $this->view->daywidth = '330';
                break;
            case 2:
                $this->view->daywidth = '165';
                break;
            case 3:
                $this->view->daywidth = '110';
                break;
            case 4:
                $this->view->daywidth = '82';
                break;
        }

        $this->view->days = $days;
        $this->display('hotel');
    }

    public function ls() {
        $this->view->actives['ls'] = ' class="active"';

        $strjson=$this->model->getFile("chain",'');
        $this->view->ls=json_decode($strjson,true);

        $this->display('ls');
    }

    public function lscity() {
        $this->view->actives['ls'] = ' class="active"';

        $id = intval($_GET['id']);
        $id=empty($id)?0:$id;
        $strjson=$this->model->getFile("chaincity",array('lsid'=>$id));
        $this->view->ls=json_decode($strjson,true);

        $this->display('lscity');
    }

    public function hotcity() {
        $this->view->actives['hotcity'] = ' class="active"';

        $strjson=$this->model->getFile("city","");
        $this->view->ls=json_decode($strjson,true);

        $this->display('hotcity');
    }

    public function hotelmap() {
        $querystr = str_replace("hotelinfo.asp?", "", $_SERVER['QUERY_STRING']);
        $queryarr = array();
        parse_str($querystr,$queryarr);
        if(!empty($queryarr['cityid']) && !empty($queryarr['hotelid'])) {
            $_GET['cid'] = $queryarr['cityid'];
            $_GET['hid'] = $queryarr['hotelid'];
            $this->hotel();
            exit;
        }
        $this->view->actives['hotelmap'] = ' class="active"';
        $cid = intval($_GET['cid']);
        $this->view->cid=empty($cid)?53:$cid;
        $this->view->url = urlencode(getsiteurl().'freeuch.php?mod=hotel&act=hotelmap&');

        $this->display('hotelmap');
    }

    public function ebook() {
        $this->view->actives['hotel'] = ' class="active"';

        $this->view->tm1=empty($_COOKIE['tm1'])?'':$_COOKIE['tm1'];
        $this->view->tm2=empty($_COOKIE['tm2'])?'':$_COOKIE['tm2'];
        $rid = intval($_GET['rid']);
        $this->view->rid=empty($rid)?'':$rid;
        $this->view->url = urlencode(getsiteurl().'freeuch.php?mod=hotel&');

        $this->display('ebook');
    }

    public function orderlist() {
        $this->view->actives['index'] = ' class="active"';

        $mobile=intval($_POST['mobile']);
        $this->view->mobile = $mobile;
        $oname=Util_Common::getstr($_POST['oname'],0,1,1);
        $strjson=$this->model->getFile("orderinfo",array('mobile'=>$mobile,'oname'=>$oname));
        $this->view->json=json_decode($strjson,true);

        $this->display('orderlist');
    }

    public function test() {
        //$a = file_get_contents("http://un.zhuna.cn/api/utf-8/hotelinfo.asp?u=276278&m=f40aafae344e2004&hid=4881&cityid=53");
        //file_put_contents(FREEUCH_ROOT.'data/a.data', $a);
        $xml = FREEUCH_ROOT.'data/a.data';
        $dom = new DOMDocument();
        $dom->load($xml);
        $xml_value = $dom->getElementsByTagName('Traffic');//标签
        print_r($xml_value->item(0)->nodeValue);
        exit;
        foreach($xml_value as $value) {
            echo $value->nodeValue;
        }

    }

    public function help() {
        $this->view->actives['help'] = ' class="active"';

        $this->display('help');
    }
}